package ws.db.sql;

import java.util.ArrayList;
import java.util.Iterator;

import ws.db.ColumnValuePair;

public class UpdateCountSQL extends SQL {

	
	
	protected ArrayList<ColumnValuePair> columnValues;
	
	public UpdateCountSQL(String m_table,ArrayList<ColumnValuePair> m_columnValues){
		super(m_table);
		columnValues = m_columnValues;
	}
	
	public UpdateCountSQL(String m_table, String m_where,
							ArrayList<ColumnValuePair> m_columnValues){
		this(m_table,m_columnValues);
		where = m_where;
	}
	
	/**
	 * Get the Update SQL which update the record visited count.
	 * @param:
	 * 		void
	 * @return:
	 * 		String - the Update Count SQL. 
	 * */
	@Override
	public String getSQL() {
		// TODO Auto-generated method stub
		StringBuffer sql = new StringBuffer();
		sql.append("update ");
		sql.append(table);
		sql.append(" set ");	
		Iterator its = columnValues.iterator();
		int i=1;
		while(its.hasNext()){
			ColumnValuePair eachpair = (ColumnValuePair)its.next();
			sql.append(eachpair.column);
			sql.append(" = ");
			sql.append(eachpair.value);
			if(i!=columnValues.size()){
				sql.append(",");
				i++;
			}
			
		}
		dealwithWhereOrder(sql,where);
		sql.append(";");
		return sql.toString();
	}

}
